package Com.aop.pojo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

import java.sql.SQLException;

public class bankServer {
    @Autowired
    private TransactionTemplate template;
    @Autowired
    private BankDaoImpl bankDao;

@Transactional(isolation = Isolation.REPEATABLE_READ,
propagation = Propagation.REQUIRED,readOnly = false)
     public  void Transfer(final String from , final String to, final int money) throws SQLException {

        try {
            bankDao.jia_money(from,money);
            bankDao.jian_money(to,money);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

/*

    public  void Transfer(final String from , final String to, final int money) throws SQLException {
        template.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                try {
                    bankDao.jian_money(from,money);
                    bankDao.jia_money(to,money);
                } catch (SQLException e) {
                    e.printStackTrace();
                }

            }
        });

*/

    }

